﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string s = textBox1.Text;
            if (s.Length != 1)
            {
                MessageBox.Show("只能输入1个字符！");
                textBox1.Text = "";
                textBox1.Focus();
                return;
            }
            char c = s[0];
            int loopCount, baseNum;
            if (Char.IsNumber(c)) 
                baseNum = 48;
            else if (Char.IsUpper(c))
                baseNum = 65;
            else if (Char.IsLower(c)) 
                baseNum = 97;
            else
            {
                MessageBox.Show("您输入的字符不合法，只能是大小写字母或数字1-9；");
                textBox1.Text = "";
                textBox1.Focus();
                return;
            }
            if (Char.IsNumber(c))
                loopCount = c - '0' + 1;
            else
             loopCount = c - baseNum + 1;
            label3.Text = "";
            for (int i = 0; i < loopCount; i++)
            {
                for (int j =0;j< loopCount - i - 1; j++) 
                {
                    label3.Text += " ";
                }
                char currentChar = (char)(baseNum + i);
                for (int k = 0; k < 2 * i + 1; k++)
                {
                    label3.Text += (char)(baseNum + i);
                }
                label3.Text += "\r\n";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            label3.Text = "输出结果";
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label3.Text = "输出结果";
        }
    }
}
